<?php 

$name = array(
	'name'	=> 'name',
	'id'	=> 'name',
	'value' => set_value('name', isset($elemento)?$elemento->link_name:""),
	'class'	=> 'text-input medium-input'
);

$url = array(
	'name'	=> 'url',
	'id'	=> 'url',
	'value' => set_value('url', isset($elemento)?$elemento->link_url:""),
	'class'	=> 'text-input medium-input'
);

$target_options = array(
	""			=> "En la misma ventana",
	"_blank"	=> "En otra ventana"
);
$target_value = set_value("target", isset($elemento)?$elemento->link_target:"_blank");

$status_options = array(
	'active'	=> "Activo",
	'inactive'	=> "Inactivo"
);
$status_value = set_value('status', isset($elemento)?$elemento->link_status:"inactive");

?>




<div class="content-box"><!-- Start Content Box -->
				
	<div class="content-box-header">
		
		<h3>
			<?php if(isset($id)): ?>
				Editar Enlace
			<?php else:?>
				Añadir un nueve Enlace
			<?php endif;?>
			
		</h3>
		
		<?php if(isset($extra_fields)): ?>
		<ul class="content-box-tabs">
			<li><a class="default-tab" href="#form-form">Formulario</a></li> <!-- href must be unique and match the id of target div -->
			<li><a href="#form-categories">Categorias</a></li>
			<li><a href="#form-extra">Información Extra</a></li>
			
		</ul>
		<?php endif; ?>
				
		<div class="clear"></div>
		
	</div> <!-- End .content-box-header -->
	
	<div class="content-box-content">
					
	<?php echo form_open($this->uri->uri_string()); ?>
		
		<fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
			
			<div id="form-form" class="default-tab tab-content">
				<p>
					<label>Nombre</label>
					<?php echo form_input($name); ?>
				</p>
				
				<p>
					<label>Url</label>
					<?php echo form_input($url); ?>
				</p>
	
				<p>
					<label>Target</label>
					<?php echo form_dropdown('target', $target_options, $target_value, 'class="small-input"'); ?>
				</p>
	
				
				<p>
					<label>Estado</label>
					<?php echo form_dropdown('status', $status_options, $status_value, 'class="small-input"'); ?>
				</p>
			
			</div>
			
			<?php if(isset($extra_fields)): ?>
				<div id="form-extra" class="tab-content" style="display: none">
				<?php foreach($extra_fields as $param_key=>$param_info): ?>
			
				<p>
					<?php $this->load->view($template_path . 'utils/autogenerate_form_fields', array("field_name" => $param_key, "field" => $param_info)); ?>
				</p>
				
				<?php endforeach; ?>
				</div>
			<?php endif;?>
			
			<div id="form-categories" class="tab-content" style="display: none">
				<p>
					<?php $this->load->view($template_path . 'utils/categories', array("field_name" => 'categories', "field_title" => "Categorias", "categories" => $categorias, "selected_categories" => isset($selected_categories)?$selected_categories:array())); ?>
				</p>
			</div>
			
			<p class="align-left">
				<input class="button" type="button" name="cancel" value="Cancelar" />
			</p>
			
			<p class="align-right">
				<?php if(isset($id)): ?>
				<input class="button" type="submit" value="Editar Enlace" />
				<?php else: ?>
				<input class="button" type="submit" value="Crear Enlace" />
				<?php endif; ?>
			</p>
			
			
			<div class="clear"></div>
			
		</fieldset>
		
		<div class="clear"></div><!-- End .clear -->

		
	<?php echo form_close(); ?>
	
</div> <!-- End #tab2 -->  


</div>


<script type="text/javascript">
	$(document).ready(function(){
		$("form *[name=cancel]").click(function(){
			window.location.href="<?php echo $referrer; ?>";
		})
	})
</script>
